﻿namespace SharePointCSVImporter.RuleEditors
{
    using System.Windows;
    using System.Windows.Controls;

    public partial class LookupReplace : UserControl
    {
        #region Fields

        CSVParser.FieldMapping _mapping;

        #endregion Fields

        #region Constructors

        public LookupReplace(ref CSVParser.FieldMapping mapping)
        {
            InitializeComponent();
            this._mapping = mapping;
            if (mapping != null && mapping.Transformation != null  && !string.IsNullOrEmpty(mapping.Transformation.TransformValue))
            {
                this.LookupValues.Text = mapping.Transformation.TransformValue;
            }
        }

        #endregion Constructors

        #region Methods

        private void InstructionCloseBtn_Click(object sender, RoutedEventArgs e)
        {
            this.InstructionsPopup.IsOpen = false;
        }

        private void LookupValues_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(LookupValues.Text))
            {
                _mapping.Transformation.TransformValue = LookupValues.Text;
            }
        }

        private void ShowInstructionButton_Click(object sender, RoutedEventArgs e)
        {
            this.InstructionsPopup.IsOpen = true;
        }

        #endregion Methods
    }
}